/*     */ package com.zimbra.cs.server;
/*     */ 
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.account.Server;
/*     */ import com.zimbra.cs.imap.ImapConfig;
/*     */ import com.zimbra.cs.imap.ImapServer;
/*     */ import com.zimbra.cs.imap.NioImapServer;
/*     */ import com.zimbra.cs.imap.TcpImapServer;
/*     */ import com.zimbra.cs.lmtpserver.LmtpConfig;
/*     */ import com.zimbra.cs.lmtpserver.LmtpServer;
/*     */ import com.zimbra.cs.lmtpserver.TcpLmtpServer;
/*     */ import com.zimbra.cs.milter.MilterConfig;
/*     */ import com.zimbra.cs.milter.MilterServer;
/*     */ import com.zimbra.cs.pop3.NioPop3Server;
/*     */ import com.zimbra.cs.pop3.Pop3Config;
/*     */ import com.zimbra.cs.pop3.Pop3Server;
/*     */ import com.zimbra.cs.pop3.TcpPop3Server;
/*     */ import com.zimbra.cs.util.ZimbraApplication;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public final class ServerManager
/*     */ {
/*     */   private LmtpServer lmtpServer;
/*     */   private Pop3Server pop3Server;
/*     */   private Pop3Server pop3SSLServer;
/*     */   private ImapServer imapServer;
/*     */   private ImapServer imapSSLServer;
/*     */   private MilterServer milterServer;
/*  45 */   private static final ServerManager INSTANCE = new ServerManager();
/*     */   
/*     */ 
/*  48 */   private static final boolean NIO_ENABLED = Boolean.getBoolean("ZimbraNioEnabled");
/*     */   
/*     */   public static ServerManager getInstance() {
/*  51 */     return INSTANCE;
/*     */   }
/*     */   
/*     */   public void startServers() throws ServiceException {
/*  55 */     ZimbraApplication app = ZimbraApplication.getInstance();
/*  56 */     if (app.supports(LmtpServer.class)) {
/*  57 */       startLmtpServer();
/*     */     }
/*  59 */     if (app.supports(Pop3Server.class)) {
/*  60 */       if (isEnabled("zimbraPop3ServerEnabled")) {
/*  61 */         this.pop3Server = startPop3Server(false);
/*     */       }
/*  63 */       if (isEnabled("zimbraPop3SSLServerEnabled")) {
/*  64 */         this.pop3SSLServer = startPop3Server(true);
/*     */       }
/*     */     }
/*  67 */     if (app.supports(ImapServer.class)) {
/*  68 */       if (isEnabled("zimbraImapServerEnabled")) {
/*  69 */         this.imapServer = startImapServer(false);
/*     */       }
/*  71 */       if (isEnabled("zimbraImapSSLServerEnabled")) {
/*  72 */         this.imapSSLServer = startImapServer(true);
/*     */       }
/*     */     }
/*     */     
/*     */ 
/*  77 */     if ((app.supports(MilterServer.class)) && 
/*  78 */       (LC.milter_in_process_mode.booleanValue())) {
/*  79 */       this.milterServer = startMilterServer();
/*     */     }
/*     */   }
/*     */   
/*     */   private static boolean isEnabled(String key) throws ServiceException
/*     */   {
/*  85 */     return Provisioning.getInstance().getLocalServer().getBooleanAttr(key, false);
/*     */   }
/*     */   
/*     */   private LmtpServer startLmtpServer() throws ServiceException {
/*  89 */     LmtpConfig config = LmtpConfig.getInstance();
/*  90 */     LmtpServer server = new TcpLmtpServer(config);
/*  91 */     server.start();
/*  92 */     return server;
/*     */   }
/*     */   
/*     */   private Pop3Server startPop3Server(boolean ssl) throws ServiceException {
/*  96 */     Pop3Config config = new Pop3Config(ssl);
/*  97 */     Pop3Server server = (NIO_ENABLED) || (LC.nio_pop3_enabled.booleanValue()) ? new NioPop3Server(config) : new TcpPop3Server(config);
/*     */     
/*  99 */     server.start();
/* 100 */     return server;
/*     */   }
/*     */   
/*     */   private ImapServer startImapServer(boolean ssl) throws ServiceException {
/* 104 */     ImapConfig config = new ImapConfig(ssl);
/* 105 */     ImapServer server = (NIO_ENABLED) || (LC.nio_imap_enabled.booleanValue()) ? new NioImapServer(config) : new TcpImapServer(config);
/*     */     
/* 107 */     server.start();
/* 108 */     return server;
/*     */   }
/*     */   
/*     */   private MilterServer startMilterServer() throws ServiceException {
/* 112 */     MilterServer server = new MilterServer(new MilterConfig());
/* 113 */     server.start();
/* 114 */     return server;
/*     */   }
/*     */   
/*     */   public void stopServers() throws ServiceException {
/* 118 */     if (this.lmtpServer != null) {
/* 119 */       this.lmtpServer.stop();
/*     */     }
/* 121 */     if (this.pop3Server != null) {
/* 122 */       this.pop3Server.stop();
/*     */     }
/* 124 */     if (this.pop3SSLServer != null) {
/* 125 */       this.pop3SSLServer.stop();
/*     */     }
/* 127 */     if (this.imapServer != null) {
/* 128 */       this.imapServer.stop();
/*     */     }
/* 130 */     if (this.imapSSLServer != null) {
/* 131 */       this.imapSSLServer.stop();
/*     */     }
/* 133 */     if (this.milterServer != null) {
/* 134 */       this.milterServer.stop();
/*     */     }
/*     */   }
/*     */   
/*     */   public LmtpServer getLmtpServer() {
/* 139 */     return this.lmtpServer;
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/server/ServerManager.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */